package kuang;

/**
 * @author cyt
 * @create 2020-03-07 16:19
 */
public class DeadLock {
    public static void main(String[] args) {
        new Makeup(0, "cyt").start();
        new Makeup(1, "yuan hui").start();
    }

}

class Lipstick {
}

class Mirror {
}

class Makeup extends Thread {
    private Integer choice;
    private String name;

    static Mirror mirror = new Mirror();
    static Lipstick lipstick = new Lipstick();


    public Makeup(Integer choice, String name) {
        this.choice = choice;
        this.name = name;
    }

    private void make() {
        if (choice == 0) {
            synchronized (mirror) {
                System.out.println("得到镜子的锁");
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
            synchronized (lipstick) {
                System.out.println("得到口红的锁");
            }
        } else {
            synchronized (lipstick) {
                System.out.println("得到口红的锁");
                try {
                    Thread.sleep(2000);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
            synchronized (mirror) {
                System.out.println("得到镜子的锁");
            }
        }
    }

    @Override
    public void run() {
        make();
    }
}
